package com.lsk.admin.shop;

import com.jfinal.aop.Duang;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.redis.Cache;
import com.jfinal.plugin.redis.Redis;
import com.jfinal.upload.UploadFile;
import com.lsk.qiniu.QiniuController;
import com.lsk.util.*;

import java.io.File;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/7/16 0016.
 */
public class ShopController extends Controller {
    ShopServices shopServices = new ShopServices();
    ShopServices txShopServices = Duang.duang(new ShopServices());

    Cache cache= Redis.use("ACTIVITYUSER");
    /**
     * 商品列表
     */
    public void commodityList() {


        String userId=getSession().getAttribute("userId").toString();
        String page = getPara("page");
        page = page == null || "".equals(page) ? "1" : page;
        String limit = getPara("limit");
        limit = limit == null || "".equals(limit) ? "10" : limit;
        PageUtil pageUtil = shopServices.commodityListService(page, limit,userId);
        setAttr("pageUtil", pageUtil);
        renderJsp("commodityList.jsp");

    }
    public void toCommoditySlideShow(){
        String commodityId=getPara("commodity");
        PageUtil pageUtil=shopServices.getCommoditySlideShowByCommodityId(commodityId);
        setAttr("commodityId",commodityId);
        setAttr("listSlid",pageUtil.getList());
        renderJsp("slideshowlunbo.jsp");
    }
    /**
     * 去商品编辑页面
     */
    public void commodityEdit() {
        String id = getPara("id"); //商品id
        String userId=getSession().getAttribute("userId").toString();
        String shopId=shopServices.findShop(userId);
        List<Record> oneClass=shopServices.firstClass(shopId);  //一级分类返显
        List<Record> peopleTypeList=shopServices.findAllticketTypeBysysId("ticket_person_type",userId);//人员类型
        List<Record> ticket_typeList=shopServices.findAllticketTypeBysysId("ticket_type",userId);//票种
        setAttr("oneClass",oneClass);
        setAttr("peopleTypeList",peopleTypeList);
        setAttr("ticket_typeList",ticket_typeList);
        List<Record> ticket_methodList=shopServices.findAllticketTypeBysysId("ticket_method",userId);
        setAttr("ticket_methodList",ticket_methodList);
        Record record=new Record();  //商品对象

        if(id!=null){
            record=shopServices.findTicketdetail(id);
            setAttr("record",record);

            Record twoClass=shopServices.ClassDetail(String.valueOf(record.get("classId")) ); //返显的二级分类

            if (twoClass!=null){
                String aa=twoClass.get("parentId");
                Record one=shopServices.ClassDetail(aa); //返显的一级分类
                setAttr("twoClass",twoClass);
                setAttr("one",one);
            }
        }
        renderJsp("editCommodity.jsp");
    }
    /**
     * 根据一级分类Id查询下面的二级分类
     * @param
     * @return
     */
    public void twolevelClass(){
        String parentId=getPara("parentId");
        List<Record> list=shopServices.twolevelClass(parentId);
        renderJson(list);
    }


    /**
     * 上传logo
     */
    public void commodityLogoImgUpload() {
        List<UploadFile> uploadFiles = getFiles();
        String commodityId = getPara("commodityId");
        Map map = shopServices.commodityLogoImgUpload(uploadFiles, commodityId);
        renderJson(map);
    }

    /**
     * 上传条形图片
     */
    public void commodityImgUpload() {
        List<UploadFile> uploadFiles = getFiles();
        String commodityId = getPara("commodityId");
        Map map = shopServices.commodityImgUpload(uploadFiles, commodityId);
        renderJson(map);
    }

    /**
     * 上传分享图片
     */
    public void commodityShareImgUpload() {
        List<UploadFile> uploadFiles = getFiles();
        String commodityId = getPara("commodityId");
        Map map = shopServices.commodityShareImgUpload(uploadFiles, commodityId);
        renderJson(map);

    }


    /**
     * 保存商品
     */
    public void saveCommodity() {

        Map<String, String[]> map = getParaMap();
        String userId=getSession().getAttribute("userId").toString();
        ReturnData returnData = shopServices.saveCommodityService(map,userId);
        renderJson(returnData);
    }


    /**
     * 删除商品
     */
    public void delCommodity() {
        String id = getPara("id").trim();
        ReturnData returnData = shopServices.delCommodityService(id);
        renderJson(returnData);
    }

    /**
     * 查看商品详情
     */
    public void selectCommodityByIdController() {
        String id = getPara("id");
        Record record = shopServices.selectCommoditByIdService(id);
        setAttr("id", id);
        setAttr("record", record);
        renderJsp("editCommodity.jsp");
    }

    /**
     * 根据parentId获取二级商品分类
     */
    public void getClssTwoByParentId(){
        String parentId=getPara("parentId");
        List<Record> list=shopServices.getClassTwoByParentId(parentId);
        renderJson(list);
    }

    /**
     * 修改商品信息
     */
    public void upCommodityInfoController() {
        Map<String, String[]> map = getParaMap();
        ReturnData returnData = shopServices.editCommodity(map);
        renderJson(returnData);
    }


    /**
     * 商品信息
     */
    public void commodityMessage() {
        String commodityId = getPara("commodityId");
        String projectPath = new GlobalParameter().projectPath;
        String content = FileUtil.readTxt(projectPath + "/commodity-message" + "/content-txt/" + "/" + commodityId + ".txt");

        String upToken=cache.get("upToken");
        if(upToken==null) {
            // 放到缓存30分钟
            upToken=QiNiuConfig.getClientTokenQiNiu(QiNiuConfig.QiNiuPath);
            cache.setex("upToken", 60 * 30, upToken);
        }
        setAttr("upToken",upToken);

        setAttr("commodityId", commodityId);
        setAttr("content", content);
        renderJsp("commodityMessage.jsp");
    }

    /**
     * 商品详情信息富文本图片上传
     */
    public void commodityMessageImgUpload() {
        String commodityId = getPara("commodityId");
        String upToken=getPara("upToken");
        List<UploadFile> uploadFiles = getFiles();
        Map map = shopServices.commodityMessageImgUploadService(uploadFiles, commodityId,upToken);
        renderJson(map);
    }

    /**
     * 保存富文本内容
     */
    public void saveMessageContent() {
        String commodityId = getPara("commodityId");
        String content = getPara("content");
        ReturnData returnData = shopServices.saveMessageContentService(commodityId, content);
        renderJson(returnData);
    }

    /**
     * 商品类别
     */

    public void classTypeList() {
        String page = getPara("page");
        String limit = getPara("limit");
        String grade = getPara("grade");
        String shopId=getSession().getAttribute("shopId").toString();
        page = page == null ? "1" : page;
        limit = limit == null ? "10" : limit;
        grade = grade == null ? "0" : grade;
        String id = getPara("id");
        PageUtil pageUtil = shopServices.shopClassOneService(Integer.parseInt(page), Integer.parseInt(limit), grade, id,shopId);
        setAttr("clist", pageUtil.getList());
        setAttr("grade", grade);
        setAttr("id", id);
        setAttr("pageUtil", pageUtil);
        setAttr("shopId",shopId);
        renderJsp("shopClassList.jsp");

    }

    /**
     * 去编辑或新增页面 ,以id是否为空判断
     */
    public void toShopClassInfo() {
        String id = getPara("id");
        String parentId=getPara("parentId");
        Record classTypeTemp = shopServices.editClassType(id);
        setAttr("id", id);
        setAttr("classRecord", classTypeTemp);
        setAttr("parentId",parentId);
        renderJsp("shopClassInfo.jsp");
    }


    /**
     * 上传商品类别图片
     */
    public void classTypeImgUpload() {
        UploadFile file = getFile();
        String uploadPath = file.getUploadPath();         //获取上传路径
        String type = file.getContentType().substring(6); //获取图片类型
        String newFilePath = uploadPath + "/" + UuidUtil.get32UUID() + "." + type;    //更换的图片名称
        newFilePath = newFilePath.replace('/', '\\');
        boolean flag = file.getFile().renameTo(new File(newFilePath));    //
        /*设置*///@TODO 已上传到tomcat/tempFile目录下
        String imgUrl = uploadPath+"\\"+new File(newFilePath).getName();

        Map map = new HashMap();
        map.put("code", "0");
        map.put("msg", "上传成功");
        Map data = new HashMap();
        data.put("src", imgUrl);
        data.put("title", "");
        map.put("data", data);
        renderJson(map);
    }

    /**
     * 保存商品类型
     */
    public void saveClass() {
        Map<String, String[]> classTypeMap = getParaMap();
        String userId=getSession().getAttribute("userId").toString();
        String shopId=shopServices.findShop(userId);
        ReturnData rd = shopServices.saveClassService(classTypeMap,shopId);
        renderJson(rd);

    }

    /**
     * 删除商品类别
     */
    public void delClass() {
        Map map = getParaMap();
        ReturnData rd = shopServices.delClassService(map);
        renderJson(rd);
    }
    /**
     * 系统参数设置
     */
    public void canshu(){
        String page=getPara("page");
        page=page==null||"".equals(page)?"1":page;
        String limit=getPara("limit");
        limit=limit==null||"".equals(limit)?"10":limit;
        PageUtil pageUtil=shopServices.showChanshu(page,limit);
        setAttr("pageUtil",pageUtil);
        renderJsp("shopCanshu.jsp");
    }
    /**
     * 修改参数设置
     */
    public void xiugaicanshu(){
        String element=getPara("element");
        String value=getPara("value");
        ReturnData returnData=shopServices.updaCanshu(element,value);
        renderJson(returnData);
    }
    /**
     * 修改显示
     */
    public void showXiugai(){
        String element=getPara("element");
        ReturnData rd=shopServices.showUpda(element);
        renderJson(rd);
    }
    /**
     * 票种管理
     */
    public void piaozhong(){
        String page=getPara("page");
        page=page==null||"".equals(page)?"1":page;
        String userId=getSession().getAttribute("userId").toString();
        String shopId=shopServices.findShop(userId);
        String limit=getPara("limit");
        limit=limit==null||"".equals(limit)?"10":limit;
        PageUtil pageUtil = shopServices.ticket(page,limit,shopId);
        setAttr("pageUtil",pageUtil);
        renderJsp("piaozhong.jsp");
    }
    /**
     * 删除票种
     */
    public void delepiao(){
        String id=getPara("id");
        ReturnData returnData=shopServices.delTicket(id);
        renderJson(returnData);
    }
    /**
     * 修改添加票种
     */
    public void updaPiao(){
        Map<String , String []> map=getParaMap();
        String shopId = getSession().getAttribute("shopId").toString();
        ReturnData returnData=shopServices.updaSave(map,shopId);
        renderJson(returnData);
    }
    /**
     * 修改显示票种
     */
    public void showSele(){
        String id=getPara("id");
        Record record=shopServices.showPiao(id);
        setAttr("record",record);
        renderJsp("updaSavePiao.jsp");
    }

    /**
     * 修改添加票种
     */
    public void show(){
        renderJsp("updaSavePiao.jsp");
    }

  /**
     * 保存商品轮播图
     */
    public void saveImages(){
        Map<String,String[]>map=getParaMap();
        ReturnData returnData =shopServices.saveImpages(map);
        renderJson(returnData);

    }

    /**
     * 加密商户列表
     */
    public void user(){
        String page = getPara("page");
        String limit = getPara("limit");
        page = page == null||"".equals(page) ? "1" : page;
        limit = limit == null||"".equals(limit) ? "10" : limit;
        PageUtil pageUtil = shopServices.allshop(page,limit);
        setAttr("pageUtil",pageUtil);
        renderJsp("shop.jsp");
    }
    /**
     * 人员类型设定
     */
    public void renyuan(){
        String page=getPara("page");
        page=page==null||"".equals(page)?"1":page;
        String limit=getPara("limit");
        limit=limit==null||"".equals(limit)?"10":limit;
        String userId=getSession().getAttribute("userId").toString();
        String shopId=shopServices.findShop(userId);
        PageUtil pageUtil=shopServices.ticketRen(page,limit,shopId);
        setAttr("pageUtil",pageUtil);
        renderJsp("renyuan.jsp");
    }
    /**
     * 删除人员类型
     */
    public void delrenyuan(){
        String id=getPara("id");
        ReturnData returnData=shopServices.delTicketRenService(id);
        renderJson(returnData);
    }
    /**
     * 修改添加人员类型
     */
    public void updaSavepersontype(){
        Map<String ,String[]> map=getParaMap();
        String userId=getSession().getAttribute("userId").toString();
        String shopId=shopServices.findShop(userId);
        ReturnData returnData=shopServices.updaSavepersontypeService(map,shopId);
        renderJson(returnData);
    }
    /**
     * 修改人员显示
     */
    public void updatePersonType(){
        String id=getPara("id");
        Record record=shopServices.updapersontypeService(id);
        setAttr("record",record);
        renderJsp("updaSaveRen.jsp");
    }

//    /**
//     * 添加商家店铺信息
//     */
    /**
     * 显示人
     */
    public void updaSaveRen(){ renderJsp("updaSaveRen.jsp");}
//    public void merchantShop(){
//        Map<String,String[]> map = getParaMap();
//        ReturnData returnData = shopServices.merChant(map);
//        renderJson(returnData);
//    }
//    public void  merChant(){
//        renderJsp("merChant.jsp");
//    }
//    /**
//     * 查询商家店铺信息
//     */
//    public void shopEnquiries(){
//        String page = getPara("page");
//        String limit = getPara("limit");
//        page = page == null ? "1" : page;
//        limit = limit == null ? "10" : limit;
//        PageUtil PageUtil = shopServices.Enquiries(Integer.parseInt(page), Integer.parseInt(limit));
//        setAttr("PageUtil",PageUtil);
//        renderJsp("shop.jsp");
//    }

    /**
     * 添加商户
     */
    public void addShop(){
        Map<String,String[]>map=getParaMap();
        ReturnData returnData =shopServices.addShop(map);
        renderJson(returnData);
    }

    /**
     * 修改商户信息
     */
    public void upShop(){

        String id=getPara("id");

        Record shop=shopServices.getShopInfoService(id);

        setAttr("shop",shop);

        renderJsp("addshop.jsp");

    }

    /**
     * 设定提款人
     */
    public void settingWithdrawer(){

        String id=getPara("id");

        String name=getPara("name");


        List<Record> memberList=shopServices.getWithdrawerByShopId(id,name);

        setAttr("shopId",id);

        setAttr("memberList",memberList);

        setAttr("name",name);

        renderJsp("settingWithdrawer.jsp");
    }

    /**
     * 保存提款人
     */
    public void saveSettingWithdrawer(){

        String memberId=getPara("memberId");

        String checked=getPara("checked");

        String shopId=getPara("shopId");

        ReturnData returnData=shopServices.saveSettingWithdrawerService(shopId,memberId,checked);

        renderJson(returnData);

    }


    //优惠券数据
    public void allcoupon(){
        String userId=getSession().getAttribute("userId").toString();
        String shopId=shopServices.findShop(userId);
        List<Record> list=shopServices.allcoupon(shopId);
        JsonUntil jsonUntil=new JsonUntil();
        jsonUntil.setCode("0");
        jsonUntil.setCount((long) 8);
        jsonUntil.setMsg("");
        jsonUntil.setData(list);
        renderJson(jsonUntil);
    }
    //添加优惠券
    public void addCoupon(){
        Map<String,String[]>map=getParaMap();
        String userId=getSession().getAttribute("userId").toString();
        ReturnData returnData =shopServices.addCoupon(map,userId);
        renderJson(returnData);

    }
    //到添加页面
    public void enterAddcoupon(){
        String id=getPara("id");
        if(id!=null) {
            Record record = shopServices.findCoupon(id);
            setAttr("record", record);
        }
        renderJsp("addcoupon.jsp");
    }
    //关联优惠券
    public void linkCoupon(){
        String userId=getSession().getAttribute("userId").toString();
        String shopId=shopServices.findShop(userId);
        List<Record> list=shopServices.allcoupon(shopId);
        String id=getPara("id"); //商品id
        setAttr("list",list);
        setAttr("id",id);
        renderJsp("linkCoupon.jsp");
    }
    //商品关联优惠券
    public void shoplinkCoupon(){
        Map<String,String[]> map=getParaMap();
        String userId=getSession().getAttribute("userId").toString();
        String shopId=shopServices.findShop(userId);
        ReturnData returnData =shopServices.shoplinkCoupon(map,shopId);
        renderJson(returnData);
    }
    //生成订单
    public void Generateorder(){
        Map<String,String[]> map=getParaMap();
        ReturnData returnData=shopServices.Generateorder(map);
        renderJson(returnData);
    }
    //购买商品
    public void buyGood(){
        Map<String,String[]> map=getParaMap();
        ReturnData returnData=shopServices.buyGood(map);
        renderJson(returnData);
    }
    //查看可用优惠券
    public void Viewavailablecoupons(){
        Map<String,String[]> map=getParaMap();
        ReturnData returnData=shopServices.Viewavailablecoupons(map);
        renderJson(returnData);
    }

    //立即使用优惠券
    public void Usecoupons(){
        Map<String,String[]> map=getParaMap();
        String couponId=map.get("couponId")[0];  //优惠券Id
        String money=map.get("money")[0]; //前台传的商品价格
        String memberId=map.get("memberId")[0]; //会员Id
        Record record=shopServices.findCoupon(couponId);
        BigDecimal newmoney=CompuUtils.subtract(money,String.valueOf(record.get("money")));
        String sql="SELECT a.* FROM yx_coupon_card a where a.couponId='"+couponId+"' and a.memberId='"+memberId+"'\n";
        Record memberCoupon= Db.findFirst(sql);
        memberCoupon.remove("state");
        memberCoupon.set("state","1"); //改变优惠状态为已使用
        Db.update("yx_coupon_card",memberCoupon);
        ReturnData returnData=new ReturnData();
        returnData.setData(newmoney);
    }
    /**
     * 专区表
     */
    public void selePrefecture(){
        String page=getPara("page");
        page=page==null||"".equals(page)?"1":page;
        String limit=getPara("limit");
        limit=limit==null||"".equals(limit)?"10":limit;
        String shopId=getSessionAttr("shopId");
        PageUtil pageUtil=shopServices.selePrefectureService(page,limit,shopId);
        setAttr("pageUtil",pageUtil);
        renderJsp("zhuanqubiao.jsp");
    }
    /**
     * 专区商品列表
     */
    public void prefectureCommodity(){

        String prefectureId=getPara("prefectureId");

        String page=getPara("page");

        page=page==null||"".equals(page)?"1":page;

        String limit=getPara("limit");

        limit=limit==null||"".equals(limit)?"10":limit;

        String shopId=getSessionAttr("shopId").toString();

        PageUtil pageUtil=shopServices.prefectureCommodityService(page,limit,prefectureId,shopId);

        setAttr("pageUtil",pageUtil);

        setAttr("prefectureId",prefectureId);

        renderJsp("prefectureCommodity.jsp");

    }
    /**
     * 修改专区商品关联
     */
    public void upPrefectureCommodity(){

        String prefectureId=getPara("prefectureId");//专区id

        String ticketId=getPara("ticketId");//商品id

        String state=getPara("state");

        ReturnData returnData= shopServices.upPrefectureCommodityService(prefectureId,ticketId,state);

        renderJson(returnData);
    }



    /**
     * 删除专区表
     */
    public void delPrefecture(){
        String id=getPara("id");
        ReturnData returnData=shopServices.delPrefectureService(id);
        renderJson(returnData);
    }
    /**
     * 修改添加专区表
     */
    public void updaSavePrefecture(){
        Map<String,String[]> map=getParaMap();
        String shopId= getSession().getAttribute("shopId").toString();
        ReturnData returnData=shopServices.updaSavePrefectureService(map,shopId);
        renderJson(returnData);
    }
    /**
     * 修改显示
     */
    public void updaPrefecture(){
        String id=getPara("id");
        Record record=shopServices.updaPrefectureService(id);
        setAttr("record",record);
        renderJsp("updaSaveZhuanqu.jsp");
    }
    /**
     * 显示修改添加
     */
    public void updaSave(){
        renderJsp("updaSaveZhuanqu.jsp");
    }

    /**
     * 轮播图列表
     */
    public void slideshowList(){
        String shopId=getSession().getAttribute("shopId").toString();
        List<Record> slideShowList = shopServices.slideShowListService(shopId);
        setAttr("slideShowList",slideShowList);
        renderJsp("homePageSlideshow.jsp");
  }

 /**
     * 编辑轮播图
     */
    public void homePageSlideshowInfo(){

        String id=getPara("id");


        renderJsp("homePageSlideshowInfo.jsp");


    }


    /**
     * 删除轮播图
     */
    public void deleteSlide(){
        String id = getPara("id");
        ReturnData returnData = shopServices.deleTeService(id);
        renderJson(returnData);
    }

    /**
     * 保存轮播图
     */
    public void saveHomePageSlideshowInfo(){

        Map<String,String[]> map=getParaMap();

        ReturnData returnData= shopServices.saveHomePageSlideshowInfoService(map);

        renderJson(returnData);

    }
    /**
     * 商品
     */
    public void navigation(){
        String page=getCookie("page");
        page=page==null||"".equals(page)?"1":page;
        String limit=getCookie("limit");
        limit=limit==null||"".equals(limit)?"10":limit;
        String shopId=getSession().getAttribute("shopId").toString();
        PageUtil pageUtil=shopServices.navigationService(page,limit,shopId);
        setAttr("pageUtil",pageUtil);
        renderJsp("navigation.jsp");
    }

    /**
     * 删除商品
     */
    public void delNavigation(){
        String id=getPara("id");
        ReturnData returnData=shopServices.delNavigationService(id);
        renderJson(returnData);
    }
    /**
     * 查询显示优惠卷
     */
    public void coupon(){
        String id=getPara("id");
        String userId=getSession().getAttribute("userId").toString();
        String shopId=shopServices.findShop(userId);
        List<Record> list=shopServices.allcoupon(shopId);
        String page=getCookie("page");
        page=page==null||"".equals(page)?"1":page;
        String limit=getCookie("limit");
        limit=limit==null||"".equals(limit)?"10":limit;
        PageUtil pageUtil=shopServices.seleCouponService(page,limit,id);
        Record record=shopServices.couponServie(id);
        setAttr("pageUtil",pageUtil);
        setAttr("list",list);
        setAttr("id",id);
        setAttr("record", record);
        renderJsp("couponcha.jsp");
    }

    /**
     * 查询微信配置
     */
    public void weChatconFiguration(){
        String shopId=getSession().getAttribute("shopId").toString();

        Record record = shopServices.weChatcon(shopId);
        setAttr("record",record);
        renderJsp("addWeChat.jsp");
    }


    /**
     * 添加修改微信配置
     */
    public void  addWeChat(){
        Map<String,String[]> map = getParaMap();
        ReturnData returnData = shopServices.addOnWeChat(map);
        renderJson(returnData);
    }
    public void  addWEChat(){
        String id=getPara("id");
        String sql = "select * from weixin_public_account_info where id='"+id+"'";
        Record record =Db.findFirst(sql);
        setAttr("record",record);
        renderJsp("addWeChat.jsp");
    }
    /**
     * 取消关联
     */
    public void delCoupon(){
        String id=getPara("id");
        ReturnData returnData=shopServices.closeCouponServie(id);
        renderJson(returnData);
    }

    //图标详情页
    public void uploadIcon() {
        String userId=getSession().getAttribute("userId").toString();
        String shopId=shopServices.findShop(userId);
        Record record=shopServices.shopDetail(shopId);
        setAttr("record",record);
        renderJsp("uploadIcon.jsp");
    }


    //跳修改商铺图标详情页
    public void uoloadIcondetail() {
        String userId=getSession().getAttribute("userId").toString();
        String shopId=shopServices.findShop(userId);
        Record record=shopServices.shopDetail(shopId);
        setAttr("record",record);
        renderJsp("uploadIconDetail.jsp");
    }

    /**
     * 提交修改图标
     */
    public void uoloadShopIcon(){
        Map<String,String[]> map = getParaMap();
        String userId=getSession().getAttribute("userId").toString();
        String shopId=shopServices.findShop(userId);
        ReturnData returnData = shopServices.uoloadShopIcon(map,shopId);
        renderJson(returnData);
    }
    /**
     * 修改加盟商
     */
    public void updaShop(){
        Map<String , String[] >map =getParaMap();
        ReturnData returnData=shopServices.updaShop(map);
        renderJson(returnData);
    }
    /**
     * 删除优惠卷
     */
    public void delyouhuijuan(){
        String id=getPara("id");
        ReturnData returnData=shopServices.delCoupon(id);
        renderJson(returnData);
    }

    /**
     * 查询商品标签
     */
    public void brandLabel(){
        String page = getPara("page");
        String limit = getPara("limit");
        page=page==null||"".equals(page)? "1":page;
        limit=limit==null||"".equals(limit)?"10":limit;
        String commodityId= getPara("commodityId");
        PageUtil pageUtil = shopServices.seleBrand(page,limit,commodityId);
        setAttr("pageUtil",pageUtil);
        setAttr("commodityId",commodityId);
        renderJsp("brandLabel.jsp");
    }
    /**
     * 添加修改商品标签
     */

    public void addLtags(){
        Map<String,String[]> map = getParaMap();
        ReturnData returnData = shopServices.addLabel(map);
        renderJson(returnData);

    }

    /**
     * 判断ID是否为空跳转
     *不为空修改，空则添加
     */
    public void displayUpdate(){
        String commodityId=getPara("commodityId");
        String id =  getPara("id");
        if (id!=null) {
            Record record = shopServices.disPlay(id);
            setAttr("record", record);
        }
        setAttr("commodityId",commodityId);
        renderJsp("upTags.jsp");
    }
    /**
     * 删除商品标签
     */
    public void deleteTags(){
        String id = getPara("id" );
        ReturnData returnData = shopServices.removeTags(id);
        renderJson(returnData);
    }


    /**
     * 取票方式
     */
    public void ticketMethod(){

        String page=getPara("page");
        page=page==null||"".equals(page)?"1":page;
        String limit=getPara("limit");
        limit=limit==null||"".equals(limit)?"10":limit;

        String userId=getSession().getAttribute("userId").toString();
        String shopId=shopServices.findShop(userId);
        PageUtil pageUtil=shopServices.ticketMethod(page,limit,shopId);
        setAttr("pageUtil",pageUtil);

        renderJsp("ticketMethod.jsp");

    }

    public void ticketMethodadd(){
        String id=getPara("id");
        Record record=shopServices.ticketMethodadd(id);
        setAttr("record",record);
        renderJsp("ticketMethodadd.jsp");
    }

    /**
     * 添加,修改取票方式
     */
    public void addticketMethod(){
        Map<String , String[] >map =getParaMap();
        String userId=getSession().getAttribute("userId").toString();
        String shopId=shopServices.findShop(userId);
        ReturnData returnData=shopServices.addticketMethod(map,shopId);
        renderJson(returnData);
    }

    public void delticketMethod(){
        String id = getPara("id" );
        ReturnData returnData = shopServices.delticketMethod(id);
        renderJson(returnData);
    }

    public void distributorList(){
        String userId=getSession().getAttribute("userId").toString();
        String page=getPara("page");
        String limit=getPara("limit");
        String memberName=getPara("memberName");
//        String type=getPara("type");
        PageUtil pageUtil=shopServices.distributorList(page, limit,userId,memberName);
        JsonUntil jsonUntil=new JsonUntil();
        jsonUntil.setCode("0");
        jsonUntil.setCount((long) pageUtil.getTotalRows());
        jsonUntil.setMsg("");
        jsonUntil.setData(pageUtil.getList());
        renderJson(jsonUntil);



    }

    /**
     * 添加 分销返利记录
     */
    public void addrebateRecord(String orderId,int money, String openId,String memberId,String state,String type ,String errCode ){
        ReturnData returnData=shopServices.addrebateRecord(orderId,money,openId,memberId,state,type,errCode);
        renderJson(returnData);
    }
    /**
     * 添加 分销返利记录
     */
    public void rebateRecord(){
        String userId=getSession().getAttribute("userId").toString();
        String shopId=shopServices.findShop(userId);
        String page=getPara("page");
        String limit=getPara("limit");
        String memberName=getPara("memberName");
//        String type=getPara("type");
        PageUtil pageUtil=shopServices.rebateRecord(Integer.parseInt(page) ,Integer.parseInt(limit) ,userId,memberName,shopId);
        JsonUntil jsonUntil=new JsonUntil();
        jsonUntil.setCode("0");
        jsonUntil.setCount((long) pageUtil.getTotalRows());
        jsonUntil.setMsg("");
        jsonUntil.setData(pageUtil.getList());
        renderJson(jsonUntil);
    }








}